#include<map>
#include<set>
#include<string>
#include<iostream>
using namespace std;
map<string, set<int>> dic; //使用map
set<int>::iterator iter; //搞一个迭代器

int main() {
    ios::sync_with_stdio(false); //调整ios
	int n, m; 
	cin >> n;
	for (int i = 1; i <= n; ++ i) {
	    int l;
	    cin >> l;
	    for (int j = 0; j < l; ++ j) {
	        string s;
	        cin >> s;
	        dic[s].insert(i);
	    }
	}
	cin >> m;
	while (m --) {
	    string s;
	    cin >> s;
	    if (dic.count(s))
	        for (iter = dic[s].begin(); iter != dic[s].end(); ++ iter)
	            cout << *iter << " ";
	    cout << endl;
	}
	return 0;
}
